/**
 * @Date 2023-02-21 10:03:49
 * @Remark
 */

// react
import React from "react";
// lib
import { Button, Popconfirm, Space } from "antd";
import { cancelOrder } from "./controller";
import { dictState } from "state/global";
// store
// controller

const TableColumns = [
  {
    title: "借阅Id",
    dataIndex: "id",
  },
  {
    title: "借阅人",
    dataIndex: "userId",
  },
  {
    title: "用户账号",
    dataIndex: "userName",
  },
  {
    title: "副本Id",
    dataIndex: "copyId",
  },

  {
    title: "书名",
    dataIndex: "title",
  },
  {
    title: "作者",
    dataIndex: "author",
  },
  {
    title: "出版社",
    dataIndex: "publisher",
  },
  {
    title: "ISBN",
    dataIndex: "isbn",
  },
  {
    title: "预约时间",
    dataIndex: "orderDate",
  },
  {
    title: "到期时间",
    dataIndex: "closeDate",
  },
  {
    title: "就绪时间",
    dataIndex: "readyDate",
  },
  {
    title: "逾期时间",
    dataIndex: "expriyDate",
  },
  {
    title: "状态",
    dataIndex: "status",
    render: (el:string) => dictState.OrderStatusList.find(item => item.code === el)?.name
  },
  {
    title: "操作",
    key: "action",
    fixed: "right" as any,
    render: (el: any) => {
      // 取消订单
      const cancel = () => {
        cancelOrder(el.id)
      };
      return (
        <Space>
          {el.status==='PENDING'&&(<Popconfirm 
            title={`确定取消预约《${el.title}》吗?`}
            onConfirm={cancel}
          >
            <Button size="small" type="primary" ghost danger>
              取消预约
            </Button>
          </Popconfirm>)}
        </Space>
      );
    },
  },
];

export default TableColumns;
